package com.wuzheng.wisgo.sanitation.cloud.controller.jobshift;


import com.wuzheng.wisgo.sanitation.cloud.model.jobshift.BaJobShiftCriteria;
import com.wuzheng.wisgo.sanitation.cloud.paraandgetutil.VehicleException;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.jobshift.BaJobShift;
import com.wuzheng.wisgo.sanitation.cloud.service.jobshift.BaJobShiftService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author：sp
 * @date：Created in 2019-12-12
 * @description：作业班次控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/baJobShift")
@Api(value = "BaJobShiftCtrl", tags = "作业班次接口")
public class BaJobShiftCtrl extends BaseController {

    @Autowired
    private BaJobShiftService baJobShiftService;

    /**
     * 获取作业班次列表
     */
    @PostMapping(value = "/list")
    @ApiOperation(value = "获取作业班次列表")
    public Result<List<BaJobShift>> fetchList(@RequestBody BaJobShiftCriteria baJobShiftCriteria) {
        //查询未删除的数据
        baJobShiftCriteria.setDeFlag(false);
        return this.success(baJobShiftService.selectPage(baJobShiftCriteria));
    }

    /**
     * 新增作业班次
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增作业班次")
    public Result<String> add( @RequestBody BaJobShift baJobShift) {
        try {
            baJobShiftService.insertJobShift(baJobShift);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success();
    }

    /**
     * 删除作业班次
     */
    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除作业班次")
    public Result<String> delete(@PathVariable("id") String[] id) {
        try {
            baJobShiftService.deleteJobShift(id);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success("删除成功");
    }

    /**
     * 修改作业班次
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改作业班次")
    public Result<String> update( @RequestBody BaJobShift baJobShift) {
        try {
            baJobShiftService.updateJobShift(baJobShift);
        } catch (VehicleException e) {
            e.printStackTrace();
            return this.failure(e.getMessage());
        }
        return this.success();
    }

    /**
     * 获取作业班次
     */
    @GetMapping(value = "/get/{id}")
    @ApiOperation(value = "获取作业班次")
    public Result<BaJobShift> get(@PathVariable("id") String id) {
        return this.success(baJobShiftService.selectById(id));
    }
}

